<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>删除和替换节点</title>
    <style>
        *{padding: 0; margin: 0; font-size: 12px;}
        ul,li{list-style: none;}
        li{float: left; text-align: center; width: 140px;}
    </style>
</head>
<body>
    <ul>
        <li>
            <img src="images/f01.jpg" id="first">
            <p><input type="button" value="删除我吧" onclick="del()"></p>
        </li>
        <li>
            <img src="images/f02.jpg" id="second">
            <p><input type="button" value="换换我吧" onclick="rep()"></p>
        </li>
    </ul>
<script>
    function del() {
        var first=document.getElementById("first");
        first.parentNode.removeChild(first);
    }
    function rep() {
        var second=document.getElementById("second");
        var newe=document.createElement("img");
        newe.setAttribute("src","images/f03.jpg");
        second.parentNode.replaceChild(newe,second);
    }
</script>
</body>
</html>